﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class UserWork_MyPlan : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["PlanId"] != null)
            {
                this.Submit1.Visible = false;
                int PlanId = Convert.ToInt32(Request["PlanId"].ToString());
                SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
                con.Open();
                string sql = "select * from [Plan] where planid=" + PlanId + "";
                SqlCommand com = new SqlCommand(sql, con);
                SqlDataReader dr = com.ExecuteReader();
                dr.Read();
                this.txTitle.Value = dr["topic"].ToString();
                this.HtmlEditor1_HtmlEditorContent.Value = dr["Content"].ToString();
                con.Close();
            }
            else
            {
                this.Button1.Visible = false;
            }
        }
    }
    protected void Submit1_ServerClick(object sender, EventArgs e)
    {

        if (this.txTitle.Value.Trim() == "" || this.HtmlEditor1_HtmlEditorContent.Value.Trim() == "")
        {
            
            Response.Write("<script>alert('请填写完整信息！')</script>");
        }
        else
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
            con.Open();
            DateTime dt = DateTime.Now;
            string Title = this.txTitle.Value.Trim();
            string Content = this.HtmlEditor1_HtmlEditorContent.Value.ToString();
            string UserName = Session["UserName"].ToString();
            string sql = "insert  [Plan] values('" + dt + "','" + Content + "','" + Title + "','" + UserName + "')";
            SqlCommand com = new SqlCommand(sql, con);
            com.ExecuteNonQuery();
            Response.Write("<script>alert('保存成功！！');window.location.href='PlanManage.aspx';</script>");
            con.Close();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write(this.txTitle.Value);
        int PlanId = Convert.ToInt32(Request["PlanId"].ToString());
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        con.Open();
        string sql = "update [Plan] set Topic='" + this.txTitle.Value.Trim() + "',Content='" + this.HtmlEditor1_HtmlEditorContent.Value.Trim() + "' where PlanId="+PlanId+" ";
        SqlCommand com = new SqlCommand(sql,con);
        com.ExecuteNonQuery();
        Response.Write("<script>alert('修改成功！');window.location.href='PlanManage.aspx';</script>");
        con.Close();
    }
}
